package com.example.web04.utils;

/**
 * 统一结果响应：以同一个类型的结果作为响应返回
 */
public class Result {
    private Integer code;
    private String msg;
    private Object date;
    private Long timestamp;

    public Result(ResultCode resultCode,Object date){
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.date = date;
        this.timestamp = System.currentTimeMillis();

    }
    //以静态方法提供一些公用的返回方法
    //请求成功，带数据
    public static Result ok(Object date){
        return new Result(ResultCode.SUCCESS,date);
    }
    //请求成功，无数据
    public static Result ok(){
        return ok(null);
    }
    //请求失败
    public static Result error(ResultCode resultCode){
        return new Result(resultCode,"操作失败");
    }
}
